﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SmartSapce.ServiceLocation;
using SmartSpace.Core;
using SmartSpace.OA;
using SmartSpace.Web;

namespace SmartSpace.WebApp.Modules.OA.Pages
{
    public partial class Article_List : SsTemplatePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ICoreService service = ServiceLocator.Get<ICoreService>();

                List<CodeDefinition> codes = service.GetCodeDefinitions(Article.TypeCategoryCode);
                _ctlListType.DataSource = codes;
                _ctlListType.DataBind();
                _ctlListType.SelectedIndex = 0;

                IOAService oaService = ServiceLocator.Get<IOAService>();
                PagedList<Article> list =  oaService.GetArticles(_ctlListType.SelectedItem.Value, 0, 999);
                _ctlList.DataSource = list;
                _ctlList.DataBind();
            }
        }

        protected void _ctlListType_SelectedIndexChanged(object sender, EventArgs e)
        {
            IOAService oaService = ServiceLocator.Get<IOAService>();
            PagedList<Article> list = oaService.GetArticles(_ctlListType.SelectedItem.Value, 0, 999);
            _ctlList.DataSource = list;
            _ctlList.DataBind();
        }
    }
}